#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

vector<vector<int>> twoNumberSum(vector<int> &arr, int target) {
  sort(arr.begin(), arr.end());
  vector<vector<int>> result;

  for (int i = 0; i < arr.size() - 1; ++i) {
    int l = i + 1;
    int r = arr.size() - 1;

    while (l < r) {
      int sum = arr[l] + arr[r];

      if (sum == target) {
        result.push_back({arr[l], arr[r]});
        ++l;
        --r;
      }
      else if (sum > target) {
        --r;
      }
      else {
        --l;
      }
    }
  }

  return result;
}

int main(int argc, char const *argv[])
{
  vector<int> arr {8, 1, 2, 5, -3, 9};
  auto result = twoNumberSum(arr, 6);
  
  return 0;
}
